package nio.socket.nonblocking;

import java.io.IOException;

/**
 * 使用线程池对非阻塞IO进行优化示例
 * 缺点：需要通过迭代所有的SocketChannel判断是否有可以处理的请求
 * 假设一个有10000个连接，前9999个连接都没有数据要处理，刚好最后一个连接才有请求。那么前9999次都是做无用功
 */
public class ThreadPoolTimeServerTest {
    private static int port = 9999;
    private static String host = "127.0.0.1";
    public static void main(String[] args) throws InterruptedException, IOException {

        new Thread(()->{
            ThreadPoolTimeServer.start(port);
        },"server").start();

        Thread.sleep(1000);

        new Thread(()->{
            ThreadPoolTimeClient.post(host,port,3500);
        },"client1").start();

        new Thread(()->{
            ThreadPoolTimeClient.post(host,port,3500);
        },"client2").start();
    }
}
